Add input validation (min binsize 30k) and skip cells with missing VCFs - #35
Open
tdalil wants to merge 2 commits into
Open
Add input validation (min binsize 30k) and skip cells with missing VCFs#35tdalil wants to merge 2 commits into
tdalil wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens input validation and improves robustness of allele-specific CNA processing by preventing hard failures when expected per-cell inputs (BAMs/VCFs/allele counts) are missing or malformed.
Changes:
- Added early file existence validation for tumour/normal BAM inputs and restricted
buildviamatch.arg(). - Enforced a minimum
binsizeof 30k and replaced several scalar logical operators with&&/||. - Made AS-CNA phasing/VCF parsing more defensive and added skipping behavior for missing per-cell inputs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
R/run_sc_sequencing.R |
Adds/adjusts early input validation, minimum binsize enforcement, and a few logical/robustness tweaks in the sequencing pipeline. |
R/getAS_CNA.R |
Adds more robust VCF parsing and per-cell file checks to avoid crashing AS-CNA when inputs are missing/defective. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if(is.null(barcodes_10x)) | ||
| { | ||
| if(!is.null(normal_bams[1]) & is.null(res$nlCTS.normal)) | ||
| if(!is.null(normal_bams[1]) && is.null(res$nlCTS.normal)) |
| if(is.null(tumour_bams)) stop("tumour_bams cannot be NULL.") | ||
| if(!all(file.exists(tumour_bams))) stop("One or more files in tumour_bams do not exist.") | ||
| if(!is.null(normal_bams) && !all(file.exists(normal_bams))) stop("One or more files in normal_bams do not exist.") | ||
| build <- match.arg(build, choices = c("hg19", "hg38", "mm39")) |
Collaborator
There was a problem hiding this comment.
build different from hg19, hg38 and mm39 should be accepted
Comment on lines
+76
to
+77
| cmd_str <- if(grepl("\\.gz$", x, ignore.case=TRUE)) paste0("zgrep -v '^##' ", x) else paste0("grep -v '^##' ", x) | ||
| df <- as.data.frame(data.table::fread(cmd=cmd_str)) |
Comment on lines
+90
to
+93
| if(ncol(x) >= 10 && !("REF" %in% colnames(x))) { | ||
| colnames(x)[4] <- "REF" | ||
| colnames(x)[5] <- "ALT" | ||
| } |
Comment on lines
+451
to
+457
| ac_p <- if(length(list_ac_counts_paths)==1) list_ac_counts_paths[[1]] else list_ac_counts_paths[[x]] | ||
| ph_p <- if(length(path_to_phases)==1) path_to_phases[[1]] else path_to_phases[[x]] | ||
|
|
||
| if(!all(file.exists(ac_p)) || (!is.null(ph_p) && !all(file.exists(ph_p)))) { | ||
| warning(paste("Missing allele count or phasing files for cell", x, "- skipping AS CNA for this cell.")) | ||
| return(NULL) | ||
| } |
Comment on lines
+464
to
+465
| purity=if(any(grepl("refitted",names(res)))) res$allProfiles.refitted.auto[[x]]$purity else res$allSolutions[[x]]$purity, | ||
| ploidy=if(any(grepl("refitted",names(res)))) res$allProfiles.refitted.auto[[x]]$ploidy else res$allSolutions[[x]]$ploidy, |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
R/run_sc_sequencing.R:
R/getAS_CNA.R:
Optimized header removal using (z)grep -v '^##'.
Added a tryCatch fallback using data.table::fread(skip="#CHROM") if the system command fails.
Forced renaming of columns 4 and 5 to REF and ALT to prevent haplotype extraction errors.
Returns empty data (integer(0)) for defective or empty VCFs to prevent cascading downstream crashes.